var ueditor;

function postModuleAndAction(module, action) {
	var arguCount = arguments.length;
	if (arguCount == 1) {
		var trueModule = $('#pageModule').val();
		var trueAction = module;
		$('#action').val(trueAction);
		doAjax(trueModule, trueAction, 'mainArea', '0');
	}  else {
		$('#module').val(module);
		$('#action').val(action);
		doAjax(module, action, 'mainArea', '0');
	}
}

function doAction(module, action) {
	var arguCount = arguments.length;
	if (arguCount == 1) {
		var trueModule = $('#pageModule').val();
		var trueAction = module;
		doAjax(trueModule, trueAction, 'hiddenSpan', '1');
	}  else {
		doAjax(module, action, 'hiddenSpan', '1');
	}
}

function openInfoWindow(module, action) {
	var arguCount = arguments.length;
	if (arguCount == 1) {
		var trueModule = $('#pageModule').val();
		var trueAction = module;
		doAjax(trueModule, trueAction, 'windowInsideDIV', '2');
	} else {
		doAjax(module, action, 'windowInsideDIV', '2');
	}
}

function refreshItem(module, action, item) {
	var arguCount = arguments.length;
	if (arguCount == 1) {
		var trueModule = $('#pageModule').val();
		var trueAction = 'refresh' + module;
		var trueItem = module;
		doAjax(trueModule, trueAction, trueItem, '3');
	} else if (arguCount == 2) {
		var trueModule = $('#pageModule').val();
		var trueAction = module;
		var trueItem = action;
		doAjax(trueModule, trueAction, trueItem, '3');
	} else {
		doAjax(module, action, item, '3');
	}
}

function doAjax(module, action, item, type) {
	document.getElementById("requestType").value = type;
	document.getElementById("module").value = module;
	document.getElementById("action").value = action;
   	// 打开等待
	$("#mask2").css("visibility", "visible").css('height', $(document).height());
    var options = { 
		type:'POST', 
		dataType: 'html',
		success: function(html) {
			try {
				// 关闭等待
				$("#mask2").css("visibility", "hidden").css('height', '0px');
				if (type == '1') {
					eval(html);
				}
				else if (type == '2') {
					if (html.indexOf('reDispatchFlag') != -1) {
						html = html.replace('reDispatchFlag', '');
						eval(html);
					} else {
						$('#' + item).html(html);
						showWindow("infoWindow");
					}
   				} else {
   					$('#' + item).html(html);
   				}
			} catch(e) {
				// 关闭等待
				$("#mask2").css("visibility", "hidden").css('height', '0px');
		    } finally {
		    }
   		},
   		error: function() {
   			// 关闭等待
			$("#mask2").css("visibility", "hidden");
   			alert("服务器忙，请稍后重试！");
   		}
     };
    
    $('#mainForm').ajaxSubmit(options); 
}

function initUeditor() {
	ueditor = UE.getEditor('ueditor');
	if (ueditor.getContentTxt() == "") {
		ueditor.execCommand( 'fontsize', '12px' );
	}
}